package com.ja.openchat.views;

import androidx.recyclerview.widget.DiffUtil;
import com.zy.openchat.core.model.message.ChatInfo;

import java.util.List;

public class ChatDiffCallBack extends DiffUtil.Callback{

    private List<ChatInfo> mOldDatas, mNewDatas;

    public ChatDiffCallBack(List<ChatInfo> oldDatas, List<ChatInfo> newDatas) {
        this.mOldDatas = oldDatas;
        this.mNewDatas = newDatas;
    }

    @Override
    public int getOldListSize() {
        return mOldDatas != null ? mOldDatas.size() : 0;
    }

    // 新数据集 size
    @Override
    public int getNewListSize() {
        return mNewDatas != null ? mNewDatas.size() : 0;
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        return mOldDatas.get(oldItemPosition).chatId() == mNewDatas.get(newItemPosition).chatId();
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        ChatInfo oldChat = mOldDatas.get(oldItemPosition);
        ChatInfo newChat = mNewDatas.get(newItemPosition);
        if(oldChat.chatId() != newChat.chatId()) return false;
        if(oldChat.unread_count != newChat.unread_count
                ||oldChat.unread_mention_count != newChat.unread_mention_count) return false;
        if(oldChat.isGroup()){

        }else{

        }
        if(oldChat.lastMessage!=null&&newChat.lastMessage!=null){
            if(oldChat.lastMessage.id != oldChat.lastMessage.id) return false;
            else return true;
        }else return false;
    }
}
